<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel common\models\CommentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '评论管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="comment-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>

    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
//            ['class' => 'yii\grid\SerialColumn'],

            //'id',
            [
                    'attribute' => 'id',
                    'contentOptions'    => ['width' => '30px']
            ],
            //'content:ntext',
            [
                    'attribute' => 'content',
                    'value'     => 'beginning'
            ],
            [
                   'attribute'  => 'status',
                   'value'      => 'status0.name',
                   'filter'     => \common\models\Commentstatus::find()
                   ->select(['name','id'])
                   ->orderBy('position')
                   ->indexBy('id')
                   ->column(),
                    'contentOptions' =>
                    function($model)
                    {
                        return ($model->status == 1) ? ['class' => 'bg-danger'] : [];
                    }
            ],
            'create_time:datetime',
//            'userid',
            [
                'attribute' => 'username',
                'label' => '作者',
                'value' => 'user.username'
            ],
            //'email:email',
            //'url:url',
            //'post_id',

            [
                    'class' => 'yii\grid\ActionColumn',
                    'template' => '{view}{update}{delete}{approve}',
                    //'controller' => 'test',
                    'buttons'   =>
                    [
                            'approve' => function($url, $model, $key)
                            {
                                $options = [
                                        'title' => Yii::t('yii', '审核'),
                                        'aria-label' => Yii::t('yii', '审核'),
                                        'data-confirm' => Yii::t('yii','您确定通过这条评论吗?'),
                                        'data-method' =>'post',
                                        'data-pjax' => 0,
                                ];
                                return Html::a('<spn class="glyphicon glyphicon-check"></spn>', $url, $options);
                            }
                    ],
            ],
        ],
    ]); ?>
</div>
